<template>
  <div>
    <div class="his-hot" v-show="isShowHistory">
      <div class="hd">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearHistory" />
      </div>

      <div class="bd">
        <van-tag @click="tagClick(item)" plain type="default" v-for="(item, index) in historyList"
          :key="index">{{ item }}</van-tag>
      </div>
    </div>

    <div class="his-hot">
      <div class="hd">
        <h4>热门搜索</h4>
      </div>

      <div class="bd">
        <van-tag @click="tagClick(item.keyword)" plain type="default" v-for="(item, index) in hotKeywordList" :key="index"
          :class="item.is_hot ? 'red' : ''">{{ item.keyword }}</van-tag>
      </div>
    </div>
  </div>
</template>

<script>
import { clearHistory } from '@/request/api.js'
export default {
  props: ['historyList', 'hotKeywordList'],
  data() {
    return {
      isShowHistory: true
    }
  },
  methods: {
    tagClick(value) {
      this.$emit('tagClick', value)
    },
    async clearHistory() {
      const res = await clearHistory()
      if (res.errno == 0) {
        setTimeout(() => {
          this.isShowHistory = false
        }, 1000)
        return this.$toast.success('清除成功！')
      }
      this.$toast.fail('清除失败！');

    }
  }
}
</script>

<style lang="less" scoped>
.his-hot {
  background-color: #fff;
  padding: 0.1rem;
  margin-bottom: 0.2rem;
}

.hd {
  display: flex;
  justify-content: space-between;
  font-size: 0.17rem;

  h4 {
    font-size: 0.17rem;
  }

  margin-bottom: 0.10rem;
}

.van-tag {
  margin-left: 0.05rem;
  margin-bottom: 0.1rem;
  padding: 0.05rem;
}

.red {
  color: red !important;
}</style>